package Test.designmodel.singleton;

/**
 * @Title: ecology-idea
 * @Company: 泛微软件
 * @author: weaver.Dusongsong
 * @version: 1.0
 * @CreateDate: 2022-05-18
 * @Description: ${description}
 * @ModifyLog:
 **/

public class HungrySingletonDemo {
    public static void main(String[] args) {
        Manager manager1 = Manager.getInstance();
        manager1.getName();
        Manager manager2 = Manager.getInstance();
        manager2.getName();
        if(manager2==manager2){
            System.out.println("他们是同一人！");
        }else {
            System.out.println("他们不是同一人！");
        }
    }
}

class Manager{
    private static volatile Manager instance = new Manager();

    private Manager(){

    }
    public static synchronized Manager getInstance(){
        return instance;
    }

    public void getName(){
        System.out.println("我是酒店经理：王小二。");
    }
}
